      PROGRAM LAPLACE
      REAL F(:,:), DF(:,:)
      REAL HF(:,:)
      LOGICAL CMASK (:,:)
      INTEGER MAXX, MAXY
      REAL FMAX
      INTEGER ITER
c 
c     read in sizes 
c
      PRINT *,'MAXX = (z.B. 64) '
      READ *,MAXX
      PRINT *,'MAXY = (z.B. 64) '
      READ *,MAXY
      ALLOCATE (F(MAXX,MAXY), DF(1:MAXX,MAXY))
      ALLOCATE (HF(MAXX,1:MAXY))
      ALLOCATE (CMASK(MAXX,1:MAXY))
C
      CMASK = .FALSE.
      CMASK (2:MAXX-1,2:MAXY-1) = .TRUE.
      F = 2.
      F(:,MAXY) = 1.
      WHERE (CMASK)
          F = 0.0
      ENDWHERE
      ITER = 0
      FMAX = 1
      DO WHILE (FMAX .gt. 0.001)
         ITER = ITER + 1
         HF = CSHIFT (F,1,1)
         DF = CSHIFT (F,1,-1)
         HF = HF + DF
         DF = CSHIFT (F,2,1)
         HF = HF + DF
         DF = CSHIFT (F,2,-1)
         HF = (HF + DF) * 0.25
         DF = 0
         WHERE (CMASK)
            DF = HF - F
            F  = F + DF
         ENDWHERE
         DF = ABS(DF)
         FMAX = MAXVAL (DF)
         PRINT *,'Iteration ',ITER,'  Max = ',FMAX
      END DO
      PRINT *, ITER, ' Iterationen benoetigt'
      DEALLOCATE (CMASK, HF, DF, F)
      END 
 
